package com.scalar.forecast.forecastEntry;

import java.util.Comparator;
import java.io.Serializable;

/**
 * User: Sujan Kumar
 * Date: Feb 18, 2005
 * Time: 12:10:13 PM
 */
public class TableColumnComparator implements Comparator, Serializable
{
    int result = 0;
    public int compare( Object tableColumn1, Object tableColumn2 )
    {
        if ( !( tableColumn1 instanceof TableColumn ) || !( tableColumn2 instanceof TableColumn ) )
        {
            throw new  ClassCastException ( );
        }

        int order1 = ( ( TableColumn )tableColumn1).getSortOrder();
        int order2 = ( ( TableColumn )tableColumn2).getSortOrder();
        if( ( order1 == 0 ) && ( order2 == 0 ) )
        {
            result = 0;
        }
        else if( order1 == 0 )
        {
            result = 1;
        }
        else if( order2 == 0 )
        {
            result = -1;
        }
        else
        {
            result = order1 - order2;
        }
        return result;
    }
}
